import 'package:earclean/app/routes/app_pages.dart';
import 'package:earclean/app/util/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

// 是否登录的中间件
// 是否登录的中间件
class EnsureAuthMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    //未登录
    dynamic key = box.read("key");
    if (key == null) {
      dynamic prelogin = box.read("prelogin").toString();
      if (prelogin == '1') {
        return const RouteSettings(name: Routes.LOGIN);
      } else {
        return super.redirect(route);
      }
    } else {
      dynamic quan = box.read("quan");
      if (quan == '1') {
        String findurl = box.read("find_url") ?? "";
        return RouteSettings(
            name: Routes.WEB, arguments: {'url': findurl, 'base': true});
      } else {
        return super.redirect(route);
      }
    }
  }
}
